package com.lottery.ruok.lottrey.activity;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.content.ContextCompat;
import android.support.v4.view.ViewPager;
import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.lottery.ruok.lottrey.R;
import com.lottery.ruok.lottrey.adapter.LHCPrizeNumberAdapter;
import com.lottery.ruok.lottrey.adapter.MyViewPagerAdapter;
import com.lottery.ruok.lottrey.adapter.NumberStatisticsAdapter;
import com.lottery.ruok.lottrey.adapter.PrizeAttributeHorizontalAdapter;
import com.lottery.ruok.lottrey.adapter.PrizeNumberHorizontalAdapter;
import com.lottery.ruok.lottrey.dialog.ChooseYearDialog;
import com.lottery.ruok.lottrey.interfaces.PrizeNumberListViewLoadMoreListener;
import com.lottery.ruok.lottrey.retrofitModule.RetrofitBase;
import com.lottery.ruok.lottrey.retrofitModule.RxHelper;
import com.lottery.ruok.lottrey.retrofitModule.RxSubscribe;
import com.lottery.ruok.lottrey.retrofitModule.request.LiuhecaiPrizeResquest;
import com.lottery.ruok.lottrey.retrofitModule.response.LiuhecaiPrizeResponse;
import com.lottery.ruok.lottrey.ui.ShapeIndicatorView;
import com.lottery.ruok.lottrey.ui.widget.LiuhecaiHeadView;
import com.lottery.ruok.lottrey.ui.widget.LoadMoreListView;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import ui.NavigateBar;
import ui.OberservableScrollView;
import utils.Utils;

public class LiuhecaiPrizeActivity extends BaseActivity {
    private static final String EXTRA_CODE = "code";
    private static final String EXTRA_IS_SHOP = "extra_is_shop";

    @BindView(R.id.scrollView)
    OberservableScrollView scrollView;

    @BindView(R.id.headView)
    LiuhecaiHeadView headView;


    @BindView(R.id.navigateBar)
    NavigateBar navigateBar;
    @BindView(R.id.number_list)
    RecyclerView numberList;
    @BindView(R.id.attribute_list)
    RecyclerView attributeList;
    @BindView(R.id.condition_list)
    RecyclerView conditionList;
    @BindView(R.id.custom_indicator)
    ShapeIndicatorView customIndicator;
    @BindView(R.id.tabs)
    TabLayout tabs;
    @BindView(R.id.vp_view)
    ViewPager vpView;
    @BindView(R.id.confirm)
    TextView confirm;
    @BindView(R.id.year_text)
    TextView yearText;
    @BindView(R.id.year)
    LinearLayout year;
    @BindView(R.id.goto_top)
    ImageView gotoTop;
    private String thisYear;
    private boolean canScroll = false;
    private ArrayList<View> mViewList = new ArrayList<>();
    private ArrayList<LiuhecaiPrizeResponse> liuhecaiPrizeResponses = new ArrayList<>();
    private PrizeNumberHorizontalAdapter prizeNumberHorizontalAdapter;
    private PrizeNumberHorizontalAdapter prizeConditionHorizontalAdapter;
    private PrizeAttributeHorizontalAdapter prizeAttributeHorizontalAdapter;
    private ArrayList<NumberBean> numbers = new ArrayList<>();
    private LoadMoreListView myListView1;
    private LHCPrizeNumberAdapter LHCPrizeNumberAdapter1;
    private NumberStatisticsAdapter numberStatisticsAdapter;
    private LoadMoreListView myListView2;
    private String[] attributeArray = {"生肖", "五行", "家禽野兽", "男女生肖", "天地生肖", "四季生肖", "琴棋书画", "三色生肖"};
    private HashMap<String, ArrayList<NumberBean>> attributes = new HashMap<String, ArrayList<NumberBean>>() {{
        ArrayList<NumberBean> arrayList = new ArrayList<>();
        String[] c = new String[]{"鼠", "牛", "虎", "兔", "龙", "蛇", "马", "羊", "猴", "鸡", "狗", "猪"};
        for (String s : c) {
            NumberBean bean = new NumberBean();
            bean.setNumber(s);
            bean.setKey(s);
            arrayList.add(bean);
        }
        put("生肖", arrayList);

        arrayList = new ArrayList<>();
        c = new String[]{"金", "木", "水", "火", "土"};
        for (String s : c) {
            NumberBean bean = new NumberBean();
            bean.setNumber(s);
            bean.setKey(s);
            arrayList.add(bean);
        }
        put("五行", arrayList);

        arrayList = new ArrayList<>();
        c = new String[]{"家禽", "野兽"};
        String[] d = new String[]{"禽", "兽"};
        for (int i = 0; i < c.length; i++) {
            NumberBean bean = new NumberBean();
            bean.setNumber(c[i]);
            bean.setKey(d[i]);
            arrayList.add(bean);
        }
        put("家禽野兽", arrayList);

        arrayList = new ArrayList<>();
        c = new String[]{"男肖", "女肖"};
        d = new String[]{"男", "女"};
        for (int i = 0; i < c.length; i++) {
            NumberBean bean = new NumberBean();
            bean.setNumber(c[i]);
            bean.setKey(d[i]);
            arrayList.add(bean);
        }
        put("男女生肖", arrayList);

        arrayList = new ArrayList<>();
        c = new String[]{"天肖", "地肖"};
        d = new String[]{"天", "地"};
        for (int i = 0; i < c.length; i++) {
            NumberBean bean = new NumberBean();
            bean.setNumber(c[i]);
            bean.setKey(d[i]);
            arrayList.add(bean);
        }
        put("天地生肖", arrayList);

        arrayList = new ArrayList<>();
        c = new String[]{"春肖", "夏肖", "秋肖", "冬肖"};
        d = new String[]{"春", "夏", "秋", "冬"};
        for (int i = 0; i < c.length; i++) {
            NumberBean bean = new NumberBean();
            bean.setNumber(c[i]);
            bean.setKey(d[i]);
            arrayList.add(bean);
        }
        put("四季生肖", arrayList);

        arrayList = new ArrayList<>();
        c = new String[]{"琴肖", "棋肖", "书肖", "画肖"};
        d = new String[]{"琴", "棋", "书", "画"};
        for (int i = 0; i < c.length; i++) {
            NumberBean bean = new NumberBean();
            bean.setNumber(c[i]);
            bean.setKey(d[i]);
            arrayList.add(bean);
        }
        put("琴棋书画", arrayList);

        arrayList = new ArrayList<>();
        c = new String[]{"红肖", "蓝肖", "绿肖"};
        d = new String[]{"红", "蓝", "绿"};
        for (int i = 0; i < c.length; i++) {
            NumberBean bean = new NumberBean();
            bean.setNumber(c[i]);
            bean.setKey(d[i]);
            arrayList.add(bean);
        }
        put("三色生肖", arrayList);
    }};
    public String currentAttribute = "生肖";
    private String code;
    private boolean isShop;

    public void setYear(String year) {
        thisYear = year;
        yearText.setText(thisYear + "年");
        liuhecaiPrizeResponses.clear();
        myListView2.setHaveMoreData(true);
        myListView1.setHaveMoreData(true);
        getList(false, thisYear, 0, null);
    }

    @OnClick({R.id.confirm, R.id.year, R.id.goto_top})
    public void onViewClicked(View view) {
        if (view.getId() == R.id.year) {
            ChooseYearDialog filtrateDialog = new ChooseYearDialog();
            Bundle bundle = new Bundle();
            Date d = new Date(System.currentTimeMillis());
            SimpleDateFormat sp = new SimpleDateFormat("yyyy");
            bundle.putString("year", sp.format(d));
            filtrateDialog.setArguments(bundle);
            filtrateDialog.show(getSupportFragmentManager(), null);
        } else if (view.getId() == R.id.confirm) {
            Intent intent = new Intent(LiuhecaiPrizeActivity.this, LiuhecaiDetailActivity.class);
            intent.putExtra("code", getIntent().getStringExtra("code"));
            startActivity(intent);
        } else if (view.getId() == R.id.goto_top) {
            myListView1.setSelection(0);
            myListView2.setSelection(0);
        }
    }

    public static void startActivity(Activity activity, String code, boolean isShop) {
        Intent intent = new Intent(activity, LiuhecaiPrizeActivity.class);
        intent.putExtra(EXTRA_CODE, code);
        intent.putExtra(EXTRA_IS_SHOP, isShop);
        activity.startActivity(intent);
    }

    public static class NumberBean {
        private boolean choose;
        private String number;
        private String key;

        public String getKey() {
            return key;
        }

        public void setKey(String key) {
            this.key = key;
        }

        public boolean isChoose() {
            return choose;
        }

        public void setChoose(boolean choose) {
            this.choose = choose;
        }

        public String getNumber() {
            return number;
        }

        public void setNumber(String number) {
            this.number = number;
        }
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_lhc_prize);
        ButterKnife.bind(this);
        code = getIntent().getStringExtra(EXTRA_CODE);
        isShop = getIntent().getBooleanExtra(EXTRA_IS_SHOP, false);
        init();
    }

    private void conditionClick() {
        prizeConditionHorizontalAdapter.setOnItemClickListener(new PrizeNumberHorizontalAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(View view, int position) {
                if (attributes.get(currentAttribute).get(position).isChoose()) {
                    attributes.get(currentAttribute).get(position).setChoose(false);
                } else {
                    attributes.get(currentAttribute).get(position).setChoose(true);
                }
                prizeConditionHorizontalAdapter.notifyItemChanged(position);

                int sum = 0;
                for (int i = 0; i < attributes.get(currentAttribute).size(); i++) {
                    if (attributes.get(currentAttribute).get(i).isChoose()) {//假设选择生肖的狗
                        switch (currentAttribute) {
                            case "生肖":
                                for (int j = 0; j < liuhecaiPrizeResponses.size(); j++) {//循环到每一行
                                    for (int m = 0; m < liuhecaiPrizeResponses.get(j).sxs.size(); m++) {
                                        if (attributes.get(currentAttribute).get(i).getKey().equals(liuhecaiPrizeResponses.get(j).sxs.get(m))) {
                                            liuhecaiPrizeResponses.get(j).choosesCondition.set(m, true);
                                        }
                                    }
                                }
                                break;
                            case "五行":
                                for (int j = 0; j < liuhecaiPrizeResponses.size(); j++) {//循环到每一行
                                    for (int m = 0; m < liuhecaiPrizeResponses.get(j).wxs.size(); m++) {
                                        if (attributes.get(currentAttribute).get(i).getKey().equals(liuhecaiPrizeResponses.get(j).wxs.get(m))) {
                                            liuhecaiPrizeResponses.get(j).choosesCondition.set(m, true);
                                        }
                                    }
                                }
                                break;
                            case "家禽野兽":
                                for (int j = 0; j < liuhecaiPrizeResponses.size(); j++) {//循环到每一行
                                    for (int m = 0; m < liuhecaiPrizeResponses.get(j).qinshous.size(); m++) {
                                        if (attributes.get(currentAttribute).get(i).getKey().equals(liuhecaiPrizeResponses.get(j).qinshous.get(m))) {
                                            liuhecaiPrizeResponses.get(j).choosesCondition.set(m, true);
                                        }
                                    }
                                }
                                break;
                            case "男女生肖":
                                for (int j = 0; j < liuhecaiPrizeResponses.size(); j++) {//循环到每一行
                                    for (int m = 0; m < liuhecaiPrizeResponses.get(j).nannvs.size(); m++) {
                                        if (attributes.get(currentAttribute).get(i).getKey().equals(liuhecaiPrizeResponses.get(j).nannvs.get(m))) {
                                            liuhecaiPrizeResponses.get(j).choosesCondition.set(m, true);
                                        }
                                    }
                                }
                                break;
                            case "天地生肖":
                                for (int j = 0; j < liuhecaiPrizeResponses.size(); j++) {//循环到每一行
                                    for (int m = 0; m < liuhecaiPrizeResponses.get(j).tiandis.size(); m++) {
                                        if (attributes.get(currentAttribute).get(i).getKey().equals(liuhecaiPrizeResponses.get(j).tiandis.get(m))) {
                                            liuhecaiPrizeResponses.get(j).choosesCondition.set(m, true);
                                        }
                                    }
                                }
                                break;
                            case "四季生肖":
                                for (int j = 0; j < liuhecaiPrizeResponses.size(); j++) {//循环到每一行
                                    for (int m = 0; m < liuhecaiPrizeResponses.get(j).sijis.size(); m++) {
                                        if (attributes.get(currentAttribute).get(i).getKey().equals(liuhecaiPrizeResponses.get(j).sijis.get(m))) {
                                            liuhecaiPrizeResponses.get(j).choosesCondition.set(m, true);
                                        }
                                    }
                                }
                                break;
                            case "琴棋书画":
                                for (int j = 0; j < liuhecaiPrizeResponses.size(); j++) {//循环到每一行
                                    for (int m = 0; m < liuhecaiPrizeResponses.get(j).qinqishuhuas.size(); m++) {
                                        if (attributes.get(currentAttribute).get(i).getKey().equals(liuhecaiPrizeResponses.get(j).qinqishuhuas.get(m))) {
                                            liuhecaiPrizeResponses.get(j).choosesCondition.set(m, true);
                                        }
                                    }
                                }
                                break;
                            case "三色生肖":
                                for (int j = 0; j < liuhecaiPrizeResponses.size(); j++) {//循环到每一行
                                    for (int m = 0; m < liuhecaiPrizeResponses.get(j).sebos.size(); m++) {
                                        if (attributes.get(currentAttribute).get(i).getKey().equals(liuhecaiPrizeResponses.get(j).sebos.get(m))) {
                                            liuhecaiPrizeResponses.get(j).choosesCondition.set(m, true);
                                        }
                                    }
                                }
                                break;
                        }
                        sum++;
                    } else {
                        switch (currentAttribute) {
                            case "生肖":
                                if (liuhecaiPrizeResponses != null) {
                                    for (int j = 0; j < liuhecaiPrizeResponses.size(); j++) {//循环到每一行
                                        for (int m = 0; m < liuhecaiPrizeResponses.get(j).sxs.size(); m++) {
                                            if (attributes.get(currentAttribute).get(i).getKey().equals(liuhecaiPrizeResponses.get(j).sxs.get(m))) {
                                                liuhecaiPrizeResponses.get(j).choosesCondition.set(m, false);
                                            }
                                        }
                                    }
                                }
                                break;
                            case "五行":
                                for (int j = 0; j < liuhecaiPrizeResponses.size(); j++) {//循环到每一行
                                    for (int m = 0; m < liuhecaiPrizeResponses.get(j).wxs.size(); m++) {
                                        if (attributes.get(currentAttribute).get(i).getKey().equals(liuhecaiPrizeResponses.get(j).wxs.get(m))) {
                                            liuhecaiPrizeResponses.get(j).choosesCondition.set(m, false);
                                        }
                                    }
                                }
                                break;
                            case "家禽野兽":
                                for (int j = 0; j < liuhecaiPrizeResponses.size(); j++) {//循环到每一行
                                    for (int m = 0; m < liuhecaiPrizeResponses.get(j).qinshous.size(); m++) {
                                        if (attributes.get(currentAttribute).get(i).getKey().equals(liuhecaiPrizeResponses.get(j).qinshous.get(m))) {
                                            liuhecaiPrizeResponses.get(j).choosesCondition.set(m, false);
                                        }
                                    }
                                }
                                break;
                            case "男女生肖":
                                for (int j = 0; j < liuhecaiPrizeResponses.size(); j++) {//循环到每一行
                                    for (int m = 0; m < liuhecaiPrizeResponses.get(j).nannvs.size(); m++) {
                                        if (attributes.get(currentAttribute).get(i).getKey().equals(liuhecaiPrizeResponses.get(j).nannvs.get(m))) {
                                            liuhecaiPrizeResponses.get(j).choosesCondition.set(m, false);
                                        }
                                    }
                                }
                                break;
                            case "天地生肖":
                                for (int j = 0; j < liuhecaiPrizeResponses.size(); j++) {//循环到每一行
                                    for (int m = 0; m < liuhecaiPrizeResponses.get(j).tiandis.size(); m++) {
                                        if (attributes.get(currentAttribute).get(i).getKey().equals(liuhecaiPrizeResponses.get(j).tiandis.get(m))) {
                                            liuhecaiPrizeResponses.get(j).choosesCondition.set(m, false);
                                        }
                                    }
                                }
                                break;
                            case "四季生肖":
                                for (int j = 0; j < liuhecaiPrizeResponses.size(); j++) {//循环到每一行
                                    for (int m = 0; m < liuhecaiPrizeResponses.get(j).sijis.size(); m++) {
                                        if (attributes.get(currentAttribute).get(i).getKey().equals(liuhecaiPrizeResponses.get(j).sijis.get(m))) {
                                            liuhecaiPrizeResponses.get(j).choosesCondition.set(m, false);
                                        }
                                    }
                                }
                                break;
                            case "琴棋书画":
                                for (int j = 0; j < liuhecaiPrizeResponses.size(); j++) {//循环到每一行
                                    for (int m = 0; m < liuhecaiPrizeResponses.get(j).qinqishuhuas.size(); m++) {
                                        if (attributes.get(currentAttribute).get(i).getKey().equals(liuhecaiPrizeResponses.get(j).qinqishuhuas.get(m))) {
                                            liuhecaiPrizeResponses.get(j).choosesCondition.set(m, false);
                                        }
                                    }
                                }
                                break;
                            case "三色生肖":
                                for (int j = 0; j < liuhecaiPrizeResponses.size(); j++) {//循环到每一行
                                    for (int m = 0; m < liuhecaiPrizeResponses.get(j).sebos.size(); m++) {
                                        if (attributes.get(currentAttribute).get(i).getKey().equals(liuhecaiPrizeResponses.get(j).sebos.get(m))) {
                                            liuhecaiPrizeResponses.get(j).choosesCondition.set(m, false);
                                        }
                                    }
                                }
                                break;
                        }
                    }
                }
                if (sum == 0) {
                    for (LiuhecaiPrizeResponse liuhecaiPrizeResponse : liuhecaiPrizeResponses) {
                        for (int j = 0; j < liuhecaiPrizeResponse.choosesCondition.size(); j++) {
                            liuhecaiPrizeResponse.choosesCondition.set(j, true);
                        }
                    }
                }

                LHCPrizeNumberAdapter1.notifyDataSetChanged();
            }
        });
    }

    private void init() {
        if (getIntent().getStringExtra("code") != null) {
            if (getIntent().getStringExtra("code").equals("jslhc")) {
                navigateBar.setCenterTitle("极速六合彩");
            }else if (getIntent().getStringExtra("code").equals("js10flhc")) {
                navigateBar.setCenterTitle("十分六合彩");
            }
        }
        if (isShop) {
            confirm.setVisibility(View.VISIBLE);
        } else {
            confirm.setVisibility(View.GONE);
        }
        Date d = new Date(System.currentTimeMillis());
        SimpleDateFormat sp = new SimpleDateFormat("yyyy");
        thisYear = sp.format(d);
        yearText.setText(thisYear + "年");

        View view1 = getLayoutInflater().inflate(R.layout.view_lhc_prize1, null);
        View view2 = getLayoutInflater().inflate(R.layout.view_lhc_prize2, null);
        mViewList.add(view1);
        mViewList.add(view2);
        myListView1 = view1.findViewById(R.id.listView);
        myListView2 = view2.findViewById(R.id.listView);
        myListView1.setOnLoadMoreListener(new LoadMoreListView.OnLoadMoreListener() {
            @Override
            public void onLoadMore() {
                myListView1.setHaveMoreData(true);
                getList(false, thisYear, liuhecaiPrizeResponses.size(), new PrizeNumberListViewLoadMoreListener() {
                    @Override
                    public void onMoreData() {
                        LHCPrizeNumberAdapter1.notifyDataSetChanged();
                        numberStatisticsAdapter.notifyDataSetChanged();
                        myListView1.onLoadComplete();
                    }

                    @Override
                    public void onNoMoreData() {
                        myListView1.setHaveMoreData(false);
                    }
                });
            }

            @Override
            public void onScroll(int index) {
                if (index > 10) {
                    gotoTop.setVisibility(View.VISIBLE);
                } else {
                    gotoTop.setVisibility(View.GONE);
                }
            }
        });
        myListView2.setOnLoadMoreListener(new LoadMoreListView.OnLoadMoreListener() {
            @Override
            public void onLoadMore() {
                myListView2.setHaveMoreData(true);
                getList(false, thisYear, liuhecaiPrizeResponses.size(), new PrizeNumberListViewLoadMoreListener() {
                    @Override
                    public void onMoreData() {
                        numberStatisticsAdapter.notifyDataSetChanged();
                        LHCPrizeNumberAdapter1.notifyDataSetChanged();
                        myListView2.onLoadComplete();
                    }

                    @Override
                    public void onNoMoreData() {
                        myListView2.setHaveMoreData(false);
                    }
                });
            }

            @Override
            public void onScroll(int index) {
                if (index > 10) {
                    gotoTop.setVisibility(View.VISIBLE);
                } else {
                    gotoTop.setVisibility(View.GONE);
                }
            }
        });
        String[] titles = {"开奖号码", "号码统计"};
        MyViewPagerAdapter mAdapter = new MyViewPagerAdapter(mViewList, titles);
        vpView.setAdapter(mAdapter);
        tabs.setupWithViewPager(vpView);
        customIndicator.setupWithTabLayout(tabs);
        customIndicator.setupWithViewPager(vpView);

        LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) vpView.getLayoutParams();
        layoutParams.height = Utils.getWindowDisplay(this).heightPixels - Utils.dip2px(LiuhecaiPrizeActivity.this, 65 + 50);
        vpView.setLayoutParams(layoutParams);

        scrollView.setScrollViewListener(new OberservableScrollView.ScrollViewListener() {
            @Override
            public void onScrollChanged(OberservableScrollView scrollView, int x, int y, int oldx, int oldy) {
                if (y > Utils.dip2px(LiuhecaiPrizeActivity.this, 65)) {
                    navigateBar.setBackgroundResource(R.drawable.tops);
                    float fen = 1f * (y - Utils.dip2px(LiuhecaiPrizeActivity.this, 65)) / Utils.dip2px(LiuhecaiPrizeActivity.this, 50);
                    if (fen < 1f) {
                        navigateBar.setAlpha(fen);
                    } else {
                        navigateBar.setAlpha(1f);
                    }
                } else {
                    navigateBar.setAlpha(1f);
                    navigateBar.setBackgroundResource(0);
                }

                View view = scrollView.getChildAt(scrollView.getChildCount() - 1);
                int diff = (view.getBottom() - (scrollView.getHeight() + scrollView.getScrollY()));

                if (diff == 0) {
                    myListView1.setCanListScroll(true);
                    myListView2.setCanListScroll(true);
                    canScroll = true;
                } else {
                    if (canScroll) {
                        canScroll = false;
                        myListView1.setCanListScroll(false);
                        myListView2.setCanListScroll(false);
                    }
                }
            }
        });

        String[] b = {"正码一", "正码二", "正码三", "正码四", "正码五", "正码六", "特码"};
        for (String s : b) {
            NumberBean bean = new NumberBean();
            bean.setNumber(s);
            numbers.add(bean);
        }
        RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false);
        numberList.setLayoutManager(layoutManager);
        prizeNumberHorizontalAdapter = new PrizeNumberHorizontalAdapter(numbers, LiuhecaiPrizeActivity.this);
        numberList.setAdapter(prizeNumberHorizontalAdapter);
        DividerItemDecoration itemDecorator = new DividerItemDecoration(this, DividerItemDecoration.HORIZONTAL);
        itemDecorator.setDrawable(ContextCompat.getDrawable(this, R.drawable.shape_divider_5));
        numberList.addItemDecoration(itemDecorator);
        prizeNumberHorizontalAdapter.setOnItemClickListener(new PrizeNumberHorizontalAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(View view, int position) {
                if (numbers.get(position).isChoose()) {
                    numbers.get(position).setChoose(false);
                } else {
                    numbers.get(position).setChoose(true);
                }
                prizeNumberHorizontalAdapter.notifyItemChanged(position);

                int sum = 0;
                for (int i = 0; i < numbers.size(); i++) {
                    if (numbers.get(i).isChoose()) {
                        for (LiuhecaiPrizeResponse liuhecaiPrizeResponse : liuhecaiPrizeResponses) {
                            liuhecaiPrizeResponse.chooses.set(i, true);
                        }
                        sum++;
                    } else {
                        if (liuhecaiPrizeResponses != null) {
                            for (LiuhecaiPrizeResponse liuhecaiPrizeResponse : liuhecaiPrizeResponses) {
                                liuhecaiPrizeResponse.chooses.set(i, false);
                            }
                        }
                    }
                }
                if (sum == 0) {
                    for (LiuhecaiPrizeResponse liuhecaiPrizeResponse : liuhecaiPrizeResponses) {
                        for (int j = 0; j < liuhecaiPrizeResponse.chooses.size(); j++) {
                            liuhecaiPrizeResponse.chooses.set(j, true);
                        }
                    }
                }

                LHCPrizeNumberAdapter1.notifyDataSetChanged();
            }
        });

        RecyclerView.LayoutManager layoutManager2 = new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false);
        attributeList.setLayoutManager(layoutManager2);
        prizeAttributeHorizontalAdapter = new PrizeAttributeHorizontalAdapter(attributeArray, LiuhecaiPrizeActivity.this, currentAttribute);
        attributeList.setAdapter(prizeAttributeHorizontalAdapter);
        attributeList.addItemDecoration(itemDecorator);
        prizeAttributeHorizontalAdapter.setOnItemClickListener(new PrizeAttributeHorizontalAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(View view, int position) {
                if (!currentAttribute.equals(attributeArray[position])) {
                    currentAttribute = attributeArray[position];
                    prizeAttributeHorizontalAdapter.setChoose(currentAttribute);
                    prizeAttributeHorizontalAdapter.notifyDataSetChanged();

                    for (NumberBean numberBean : attributes.get(currentAttribute)) {
                        numberBean.setChoose(false);
                    }
                    prizeConditionHorizontalAdapter = new PrizeNumberHorizontalAdapter(attributes.get(currentAttribute), LiuhecaiPrizeActivity.this);
                    conditionList.setAdapter(prizeConditionHorizontalAdapter);
                    conditionClick();

                    for (LiuhecaiPrizeResponse liuhecaiPrizeResponse : liuhecaiPrizeResponses) {
                        for (int i = 0; i < liuhecaiPrizeResponse.choosesCondition.size(); i++) {
                            liuhecaiPrizeResponse.choosesCondition.set(i, true);
                        }
                    }
                    LHCPrizeNumberAdapter1.notifyDataSetChanged();
                }
            }
        });

        RecyclerView.LayoutManager layoutManager1 = new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false);
        conditionList.setLayoutManager(layoutManager1);
        for (NumberBean numberBean : attributes.get(currentAttribute)) {
            numberBean.setChoose(false);
        }
        prizeConditionHorizontalAdapter = new PrizeNumberHorizontalAdapter(attributes.get(currentAttribute), LiuhecaiPrizeActivity.this);
        conditionList.setAdapter(prizeConditionHorizontalAdapter);
        conditionList.addItemDecoration(itemDecorator);
        conditionClick();

        getList(true, null, 0, null);
    }

    private void getList(final boolean isFirst, String year, int sezi, final PrizeNumberListViewLoadMoreListener prizeNumberListViewLoadMoreListener) {
        RetrofitBase.getRetrofit().create(LiuhecaiPrizeResquest.class).getResult(year, getIntent().getStringExtra("code"), sezi)
                .compose(RxHelper.<ArrayList<LiuhecaiPrizeResponse>>handleResult())
                .subscribe(new RxSubscribe<ArrayList<LiuhecaiPrizeResponse>>(this) {
                    @Override
                    protected void _onNext(ArrayList<LiuhecaiPrizeResponse> liuhecaiPrizeResponse) {
                        if (isFirst) {
                            if (liuhecaiPrizeResponse.size() > 0) {

                                headView.setData(liuhecaiPrizeResponse);

                                String[] p = liuhecaiPrizeResponse.get(0).getPrize_num().split(",");
                                String[] color = liuhecaiPrizeResponse.get(0).getSebo().split(",");
                                String[] sx = liuhecaiPrizeResponse.get(0).getSx().split(",");
                                String[] wx = liuhecaiPrizeResponse.get(0).getWx().split(",");
                                if (p.length > 0 && !p[0].equals("")) {
                                    for (int i = 0; i < p.length; i++) {
                                        View areaCircle = getLayoutInflater().inflate(R.layout.framework_prize_ball, null);
                                        TextView number = areaCircle.findViewById(R.id.number);
                                        number.setText(p[i]);

                                        LinearLayout linearLayout = new LinearLayout(LiuhecaiPrizeActivity.this);
                                        linearLayout.setOrientation(LinearLayout.VERTICAL);
                                        LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(Utils.dip2px(LiuhecaiPrizeActivity.this, 34), Utils.dip2px(LiuhecaiPrizeActivity.this, 34));
                                        layoutParams.bottomMargin = Utils.dip2px(LiuhecaiPrizeActivity.this, 5);
                                        areaCircle.setLayoutParams(layoutParams);
                                        linearLayout.addView(areaCircle);

                                        TextView textView = new TextView(LiuhecaiPrizeActivity.this);
                                        if (color != null && color.length > 0 && !color[0].equals("")) {
                                            switch (color[i]) {
                                                case "blue":
                                                    areaCircle.setBackgroundResource(R.mipmap.blue_big);
                                                    break;
                                                case "red":
                                                    areaCircle.setBackgroundResource(R.mipmap.red_big);
                                                    break;
                                                case "green":
                                                    areaCircle.setBackgroundResource(R.mipmap.green_big);
                                                    break;
                                            }
                                            textView.setText(sx[i] + "  " + wx[i]);
                                            textView.setTextColor(Color.parseColor("#3f3f3f"));
                                            textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 12);
                                            textView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
                                            textView.setEms(1);
                                        }

                                        linearLayout.addView(textView);
                                        LinearLayout.LayoutParams layoutParams2 = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
                                        layoutParams2.rightMargin = Utils.dip2px(LiuhecaiPrizeActivity.this, 6);
                                        linearLayout.setLayoutParams(layoutParams2);
                                        linearLayout.setGravity(Gravity.CENTER_HORIZONTAL);
                                        headView.addView(linearLayout);

                                        if (i == p.length - 2) {//倒数第二个
                                            ImageView add = new ImageView(LiuhecaiPrizeActivity.this);
                                            add.setImageResource(R.mipmap.jiahui);
                                            LinearLayout.LayoutParams layoutParams1 = new LinearLayout.LayoutParams(Utils.dip2px(LiuhecaiPrizeActivity.this, 14), Utils.dip2px(LiuhecaiPrizeActivity.this, 14));
                                            layoutParams1.rightMargin = Utils.dip2px(LiuhecaiPrizeActivity.this, 6);
                                            layoutParams1.topMargin = Utils.dip2px(LiuhecaiPrizeActivity.this, 46);
                                            add.setLayoutParams(layoutParams1);
                                            headView.addView(add);
                                        }
                                    }
                                }
                            }
                        }

                        if (liuhecaiPrizeResponse.size() == 0) {
                            if (prizeNumberListViewLoadMoreListener != null) {
                                prizeNumberListViewLoadMoreListener.onNoMoreData();
                            } else {
                                Utils.showToast("数据暂时为空");
                            }
                            if (liuhecaiPrizeResponses.size() == 0) {
                                myListView1.setVisibility(View.INVISIBLE);
                                myListView2.setVisibility(View.INVISIBLE);
                            }
                        } else {
                            myListView1.setVisibility(View.VISIBLE);
                            myListView2.setVisibility(View.VISIBLE);
                        }

                        for (LiuhecaiPrizeResponse liuhecaiPrizeResponse1 : liuhecaiPrizeResponse) {
                            String[] s = liuhecaiPrizeResponse1.getPrize_num().split(",");
                            String[] color = liuhecaiPrizeResponse1.getSebo().split(",");
                            String[] sxs = liuhecaiPrizeResponse1.getSx().split(",");
                            String[] wxs = liuhecaiPrizeResponse1.getWx().split(",");
                            String[] qinshous = liuhecaiPrizeResponse1.getQinshou().split(",");
                            String[] tiandis = liuhecaiPrizeResponse1.getTiandi().split(",");
                            String[] nannvs = liuhecaiPrizeResponse1.getNannv().split(",");
                            String[] sijis = liuhecaiPrizeResponse1.getSiji().split(",");
                            String[] qinqishuhuas = liuhecaiPrizeResponse1.getQinqishuhua().split(",");
                            String[] sebos = liuhecaiPrizeResponse1.getSanseshengxiao().split(",");
                            String[] temas = liuhecaiPrizeResponse1.getTema().split(",");
                            String[] zonghes = liuhecaiPrizeResponse1.getZonghe().split(",");
                            liuhecaiPrizeResponse1.temas.addAll(Arrays.asList(temas));
                            liuhecaiPrizeResponse1.zonghes.addAll(Arrays.asList(zonghes));
                            for (int i = 0; i < s.length; i++) {
                                liuhecaiPrizeResponse1.colors.add(color[i]);
                                liuhecaiPrizeResponse1.prizeList.add(s[i]);
                                liuhecaiPrizeResponse1.sxs.add(sxs[i]);
                                liuhecaiPrizeResponse1.wxs.add(wxs[i]);
                                liuhecaiPrizeResponse1.qinshous.add(qinshous[i]);
                                liuhecaiPrizeResponse1.tiandis.add(tiandis[i]);
                                liuhecaiPrizeResponse1.nannvs.add(nannvs[i]);
                                liuhecaiPrizeResponse1.sijis.add(sijis[i]);
                                liuhecaiPrizeResponse1.qinqishuhuas.add(qinqishuhuas[i]);
                                liuhecaiPrizeResponse1.sebos.add(sebos[i]);
                                liuhecaiPrizeResponse1.chooses.add(true);
                                liuhecaiPrizeResponse1.choosesCondition.add(true);
                            }
                        }
                        liuhecaiPrizeResponses.addAll(liuhecaiPrizeResponse);
                        if (prizeNumberListViewLoadMoreListener == null) {
                            LHCPrizeNumberAdapter1 = new LHCPrizeNumberAdapter(liuhecaiPrizeResponses, LiuhecaiPrizeActivity.this, LiuhecaiPrizeActivity.this);
                            myListView1.setAdapter(LHCPrizeNumberAdapter1);
                            numberStatisticsAdapter = new NumberStatisticsAdapter(liuhecaiPrizeResponses, LiuhecaiPrizeActivity.this);
                            myListView2.setAdapter(numberStatisticsAdapter);
                        } else {
                            prizeNumberListViewLoadMoreListener.onMoreData();
                        }
                    }


                    @Override
                    protected boolean showDialog() {
                        return true;
                    }
                });
    }
}